<template>
<<<<<<< HEAD
  <div class="login-container">
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">

      <div class="title-container">
        <!-- <img src="@/assets/logo.png" class="sidebar-logo" style="width: 50px;"> -->
        <h3 class="title">创新森林网考</h3>
      </div>

      <el-form-item prop="userName">
        <span class="svg-container">
          <svg-icon icon-class="user" />
        </span>
        <el-input
          ref="userName"
          v-model="loginForm.userName"
          placeholder="用户名"
          name="userName"
          type="text"
          tabindex="1"
          auto-complete="on"
        />
      </el-form-item>

      <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
        <el-form-item prop="password">
          <span class="svg-container">
            <svg-icon icon-class="password" />
          </span>
          <el-input
            :key="passwordType"
            ref="password"
            v-model="loginForm.password"
            :type="passwordType"
            placeholder="密码"
            name="password"
            tabindex="2"
            auto-complete="on"
            @keyup.native="checkCapslock"
            @blur="capsTooltip = false"
            @keyup.enter.native="handleLogin"
          />
          <span class="show-pwd" @click="showPwd">
            <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
          </span>
        </el-form-item>
      </el-tooltip>

      <el-form-item prop="captcha">
        <span class="svg-container">
          <svg-icon icon-class="captcha" />
        </span>
        <el-input style="display: inline-block;height: 47px;width: 42%;"
          ref="captcha"
          v-model="loginForm.captcha"
          placeholder="验证码"
          name="captcha"
          type="text"
          tabindex="3"
          auto-complete="on"
        />
        <span class="captcha-text" style="padding: 0px 10px;background-color: rgba(255, 255, 255, 0.5);width: 80px;height: 30px;
        margin-right: 15px;margin-top: 10px;text-align: center">{{ captchaText }}</span>
        <el-button @click="refreshCaptcha" style="padding:10px 6px;margin-top: 8px;color: #111;" type="text">刷新验证码</el-button>
      </el-form-item>

      <el-checkbox v-model="loginForm.remember" style="margin-bottom: 20px;margin-left: 5px;">记住密码</el-checkbox>

      <el-button :loading="loading" type="primary" 
      style="width:100%;margin-bottom:30px;background-color: #77aa77;border: 2px solid rgba(255, 255, 255, 0.3);border-radius: 50px;" @click.native.prevent="handleLogin">登录</el-button>

    </el-form>
=======
  <div class="lowin  lowin-blue">
    <div class="lowin-brand">
      <img src="@/assets/denglulogo.png" alt="logo">
    </div>
    <div class="lowin-wrapper">
      <div class="lowin-box lowin-login">
        <div class="lowin-box-inner">
          <el-form ref="loginForm" :model="loginForm" :rules="loginRules">
            <p>创新森林</p>
            <div class="lowin-group">
              <label>用户名 </label>
              <el-input ref="userName" v-model="loginForm.userName" class="lowin-input" placeholder="用户名" name="userName" type="text" tabindex="1" auto-complete="on"/>
            </div>
            <div class="lowin-group password-group">
              <label>密码
                <router-link to="/forgot">忘记密码？</router-link>
              </label>
              <el-input  class="lowin-input" :key="passwordType" ref="password" v-model="loginForm.password" :type="passwordType"
                placeholder="密码" name="password" tabindex="2" auto-complete="on" @keyup.native="checkCapslock" @blur="capsTooltip = false" @keyup.enter.native="handleLogin"/>
            </div>

            <el-form-item prop="captcha">
            <span class="svg-container">
             <svg-icon icon-class="captcha" />
            </span>
           <el-input style="display: inline-block;height: 47px;width: 50%;"
               ref="captcha"
               v-model="loginForm.captcha"
               placeholder="验证码"
               name="captcha"
               type="text"
               tabindex="3"
               auto-complete="on"
             />
               <span class="captcha-text" style="padding: 2px 16px;
                                          background-color: #a8d5bd;
                                          color: #fff;
                                          width: 150px;height: 35px;
                                          text-align: center;margin:10px 15px 0px 10px">
                                          {{ captchaText }}</span>
                <el-button @click="refreshCaptcha" style="padding:10px 6px;margin-top: 8px;color: green;font-weight: bold" type="text">刷新</el-button>
           </el-form-item>

            <el-button :loading="loading" type="text" class="lowin-btn login-btn"  @click.native.prevent="handleLogin">登录</el-button>

            <div class="text-foot">
              还没有账号?
              <router-link to="/register" class="register-link">
                注册
              </router-link>
            </div>
          </el-form>
        </div>
        <!-- footer部分 -->
        <div class="footer">
          <p>Innoforest  @  创新森林</p>
          <p>创新森林-更适合中国宝宝的语数外</p>
        </div>
      </div>
    </div>
>>>>>>> 7ecadc8962839be4c8f71425dd0a314dc19dc738
  </div>
</template>

<script>
import { mapMutations } from 'vuex'
import loginApi from '@/api/login'

export default {
  name: 'Login',
  data () {
    const validateUsername = (rule, value, callback) => {
<<<<<<< HEAD
      if (value.length < 5) {
=======
      if (!value) {
>>>>>>> 7ecadc8962839be4c8f71425dd0a314dc19dc738
        callback(new Error('用户名不能少于5个字符'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
<<<<<<< HEAD
      if (value.length < 5) {
=======
      if (!value) {
>>>>>>> 7ecadc8962839be4c8f71425dd0a314dc19dc738
        callback(new Error('密码不能少于5个字符'))
      } else {
        callback()
      }
    }
    const validateCaptcha = (rule, value, callback) => {
      if (!value) {
        callback(new Error('验证码不能为空'))
      } else if (value.toLowerCase() !== this.captchaText.toLowerCase()) {
        callback(new Error('验证码不正确'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        userName: '',
        password: '',
<<<<<<< HEAD
        captcha: '',
=======
>>>>>>> 7ecadc8962839be4c8f71425dd0a314dc19dc738
        remember: false
      },
      loginRules: {
        userName: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }],
        captcha: [{ required: true, trigger: 'blur', validator: validateCaptcha }]
      },
      passwordType: 'password',
      capsTooltip: false,
      loading: false,
      showDialog: false,
<<<<<<< HEAD
      captchaText: ''
    }
  },
  created () {
    this.refreshCaptcha()
=======
      captchaText: '点击刷新'
    }
  },
  created () {
    // window.addEventListener('storage', this.afterQRScan)
>>>>>>> 7ecadc8962839be4c8f71425dd0a314dc19dc738
  },
  mounted () {
    if (this.loginForm.userName === '') {
      this.$refs.userName.focus()
    } else if (this.loginForm.password === '') {
      this.$refs.password.focus()
    }
  },
  destroyed () {
    // window.removeEventListener('storage', this.afterQRScan)
  },
  methods: {
    checkCapslock ({ shiftKey, key } = {}) {
      if (key && key.length === 1) {
        // eslint-disable-next-line no-mixed-operators
        if (shiftKey && (key >= 'a' && key <= 'z') || !shiftKey && (key >= 'A' && key <= 'Z')) {
          this.capsTooltip = true
        } else {
          this.capsTooltip = false
        }
      }
      if (key === 'CapsLock' && this.capsTooltip === true) {
        this.capsTooltip = false
      }
    },
    showPwd () {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleLogin () {
      let _this = this
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          loginApi.login(this.loginForm).then(function (result) {
            if (result && result.code === 1) {
              _this.setUserName(_this.loginForm.userName)
              _this.$router.push({ path: '/' })
            } else {
              _this.loading = false
<<<<<<< HEAD
              _this.$message({
                message: result.message,
                type: 'error'
              })
            }
            console.log(result)
=======
              _this.$message.error(result.message)
            }
>>>>>>> 7ecadc8962839be4c8f71425dd0a314dc19dc738
          }).catch(function (reason) {
            _this.loading = false
          })
        } else {
          return false
        }
      })
    },
    refreshCaptcha () {
      this.captchaText = Math.random().toString(36).substr(2, 6).toUpperCase()
    },
    ...mapMutations('user', ['setUserName'])
  }
}
</script>

<style lang="scss">
<<<<<<< HEAD
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg:#283443;
$light_gray:#fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 80%;

    input {
      // 背景透明
      background: transparent;
      border: 0px;
      // 去除浏览器默认的输入框样式
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;
      //光标颜色

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(168, 211, 177, 0.564);
    border-radius: 50px;
    color: #454545;
  }
}
</style>

<style lang="scss" scoped>
$bg:#60637c;
$dark_gray: black;
//svg图标颜色
$light_gray:#ffffff;
// 标题颜色

.login-container {
  min-height: 100%;
  width: 100%;
  // background-color: $bg;
  background: linear-gradient(to bottom right, #fff, #abe8c7);
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding:30px 50px 30px 50px;
    margin:150px auto auto auto;
    overflow: hidden;
    background: rgba(252, 254, 255, 0.11);
     border-radius: 10px;
    /* 添加阴影 */
    box-shadow: 0 0 20px rgba(40, 38, 39, 0.4);
  }

  .tips {
    font-size: 20px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 12px 6px 20px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    // display: flex;
    // align-items: center; /* 垂直居中 */
    position: relative;

    .title {
      font-size: 28px;
      color: #a2cda2;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }
//   .sidebar-logo {
//     margin-right: 10px; /* 标题和logo之间的间距 */
// }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }

  .captcha-text {
    display: inline-block;
    font-size: 16px;
    font-weight: bold;
    color: #000;
    padding: 6px 10px;
    background: #fff;
    border-radius: 8px;
    margin-left: 10px;
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
}
=======
  .lowin-input{
    .el-input__inner{
      background-color: transparent !important;
      border: 0px !important;
    }
  }
</style>

<style scoped>

  .lowin {
    /* variables */
    --color-primary: #44a0b3;
    --color-grey: rgba(68, 160, 179, 0.06);
    --color-dark: rgba(68, 160, 179, .5);
    --color-semidark: rgba(68, 160, 179, .5);

    text-align: center;
    margin: 60px 0 0 0;
    font-family: 'Segoe UI';
    font-size: 14px;
  }

  .lowin .lowin-wrapper {
    -webkit-transition: all 1s;
    -o-transition: all 1s;
    transition: all 1s;
    -webkit-perspective: 1000px;
    perspective: 1000px;
    position: relative;
    height: 100%;
    width: 450px;
    margin: 0 auto;
  }

  .lowin.lowin-blue {
    --color-primary: #45ad74;/* 主色调 */
    --color-grey: rgba(29, 170, 99, 0.05);/* 浅灰色调 */
    --color-dark: rgba(43, 216, 112, 0.7);/*深色色调*/
    --color-semidark: rgba(51, 154, 63, 0.45);/*半深色*/
  }

  /*选择器 .lowin a
  这是一个后代选择器，它会选中所有类名为 lowin 的元素内部的 <a> 标签
  只有在 lowin 类元素包裹下的超链接才会应用这些样式*/
  .lowin a {
    color: var(--color-primary);
    text-decoration: none;
    border-bottom: 1px dashed var(--color-semidark);
    margin-top: -3px;
    padding-bottom: 2px;
  }

  .lowin * {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }

  .lowin .lowin-brand {
    overflow: hidden;
    width: 100px;
    height: 100px;
    margin: 0 auto -50px auto;
    box-shadow: 0 4px 40px rgba(64, 99, 163, 0.1);
    padding: 10px;
    background-color: #fff;
    z-index: 1;
    position: relative;
  }

  .lowin .lowin-brand img {
    width: 100%;
  }

  .lowin .lowin-box {
    width: 100%;
    position: absolute;
    left: 0;
  }

  .lowin .lowin-box-inner {
    background-color: #fff;
    -webkit-box-shadow: 0 7px 25px rgba(0, 0, 0, .08);
    box-shadow: 0 7px 25px rgba(0, 0, 0, .08);
    padding: 60px 25px 25px 25px;
    text-align: left;
    border-radius: 3px;
  }

  .lowin .lowin-box::after {
    content: ' ';
    -webkit-box-shadow: 0 0 25px rgba(0, 0, 0, .1);
    box-shadow: 0 0 25px rgba(0, 0, 0, .1);
    -webkit-transform: translate(0, -92.6%) scale(.88);
    -ms-transform: translate(0, -92.6%) scale(.88);
    transform: translate(0, -92.6%) scale(.88);
    border-radius: 3px;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #fff;
    z-index: -1;
  }

  .lowin .lowin-box.lowin-flip {
    -webkit-transform: rotate3d(0, 1, 0, -180deg);
    transform: rotate3d(0, 1, 0, -180deg);
    display: none;
    opacity: 0;
  }

  .lowin .lowin-box p {
    color: var(--color-semidark);
    font-weight: 700;
    margin-bottom: 20px;
    text-align: center;
  }

  .lowin .lowin-box .lowin-group {
    margin-bottom: 30px;
  }

  .lowin .lowin-box label {
    margin-bottom: 5px;
    display: inline-block;
    width: 100%;
    color: var(--color-semidark);
    font-weight: 700;
  }

  .lowin .lowin-box label a {
    float: right;
  }

  .lowin .lowin-box .lowin-input {
    background-color: var(--color-grey);
    color: var(--color-dark);
    border: none;
    border-radius: 3px;
    padding: 5px 20px;
    width: 100%;
    outline: 0;
  }

  .lowin .lowin-box .lowin-btn {
    display: inline-block;
    width: 100%;
    border: none;
    color: #fff;
    padding: 15px;
    border-radius: 3px;
    background-color: var(--color-primary);
    -webkit-box-shadow: 0 2px 7px var(--color-semidark);
    box-shadow: 0 2px 7px var(--color-semidark);
    font-weight: 700;
    outline: 0;
    cursor: pointer;
    -webkit-transition: all .5s;
    -o-transition: all .5s;
    transition: all .5s;
  }

  .lowin .lowin-box .lowin-btn:active {
    -webkit-box-shadow: none;
    box-shadow: none;
  }

  .lowin .lowin-box .lowin-btn:hover {
    opacity: .9;
  }

  .lowin .text-foot {
    text-align: center;
    padding: 10px;
    font-weight: 700;
    margin-top: 20px;
    color: var(--color-semidark);
  }

  /* animation */
  .lowin .lowin-box.lowin-animated {
    -webkit-animation-name: LowinAnimated;
    animation-name: LowinAnimated;
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
    -webkit-animation-timing-function: ease-in-out;
    animation-timing-function: ease-in-out;
  }

  .lowin .lowin-box.lowin-animatedback {
    -webkit-animation-name: LowinAnimatedBack;
    animation-name: LowinAnimatedBack;
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
    -webkit-animation-timing-function: ease-in-out;
    animation-timing-function: ease-in-out;
  }

  .lowin .lowin-box.lowin-animated-flip {
    -webkit-animation-name: LowinAnimatedFlip;
    animation-name: LowinAnimatedFlip;
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
    -webkit-animation-timing-function: ease-in-out;
    animation-timing-function: ease-in-out;
  }

  .lowin .lowin-box.lowin-animated-flipback {
    -webkit-animation-name: LowinAnimatedFlipBack;
    animation-name: LowinAnimatedFlipBack;
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
    -webkit-animation-timing-function: ease-in-out;
    animation-timing-function: ease-in-out;
  }

  .lowin .lowin-brand.lowin-animated {
    -webkit-animation-name: LowinBrandAnimated;
    animation-name: LowinBrandAnimated;
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
    -webkit-animation-timing-function: ease-in-out;
    animation-timing-function: ease-in-out;
  }

  .lowin .lowin-group.password-group {
    -webkit-transition: all 1s;
    -o-transition: all 1s;
    transition: all 1s;
  }

  .lowin .lowin-group.password-group.lowin-animated {
    -webkit-animation-name: LowinPasswordAnimated;
    animation-name: LowinPasswordAnimated;
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
    -webkit-animation-timing-function: ease-in-out;
    animation-timing-function: ease-in-out;
    -webkit-transform-origin: 0 0;
    -ms-transform-origin: 0 0;
    transform-origin: 0 0;
  }

  .lowin .lowin-group.password-group.lowin-animated-back {
    -webkit-animation-name: LowinPasswordAnimatedBack;
    animation-name: LowinPasswordAnimatedBack;
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
    -webkit-animation-timing-function: ease-in-out;
    animation-timing-function: ease-in-out;
    -webkit-transform-origin: 0 0;
    -ms-transform-origin: 0 0;
    transform-origin: 0 0;
  }

  @media screen and (max-width: 320px) {
    .lowin .lowin-wrapper {
      width: 100%;
    }
    .lowin .lowin-box {
      padding: 0 10px;
    }
  }
>>>>>>> 7ecadc8962839be4c8f71425dd0a314dc19dc738
</style>
